<?php require_once LAYOUTPATH.'layout_header.php'; ?>

<?php require_once APPPATH.'views/bricabox/header.php'; ?>

<div id="superbar">
	<form action="/entries" method="post" onsubmit="return Superbar.rewriteUrl();">
		<input type="hidden" class="superbar_field" name="search" value="<?php echo @$parts['search']; ?>" />
		Show
		<select class="superbar_field" name="entry_type">
			<option<?php if (!isset($parts['entry_type']) || $parts['entry_type'] == 'all') echo ' selected="selected"'; ?> value="all">everything</option>
			<?php
			if ($content_types):
				foreach ($content_types->result() as $type):
			?>
			<option<?php if (@$name = str_replace('_', ' ', $parts['entry_type']) == $type->name) echo ' selected="selected"'; ?> value="<?php echo $type->name; ?>">just <?php echo strtolower(Inflect::pluralize($type->name)); ?></option>
			<?php
				endforeach;
			endif;
			?>
		</select>
		
		<?php if ($this->bricabox->bricabox_has_block($bricabox->id, 'tags')): ?>
		tagged
		<input type="text" class="superbar_field" name="tagged" value="<?php echo str_replace('_', ' ', str_replace(':', ',', @$parts['tagged'])); ?>" />
		<?php endif; ?>
		
		<?php if ($this->bricabox->bricabox_has_block($bricabox->id, 'categories')): ?>
		categorized
		<select class="superbar_field" name="categorized">
			<option value="-1"<?php if (!isset($parts['categorized']) || $parts['categorized'] == '-1') echo ' selected="selected"'; ?>>with anything</option>
			<?php
			if ($ctgys):
				foreach ($ctgys->result() as $ctgy):
			?>
			<option value="<?php echo $ctgy->id; ?>"<?php if (@$parts['categorized'] == $ctgy->id) echo ' selected="selected"'; ?>><?php echo $ctgy->name; ?></option>
			<?php
				endforeach;
			endif;
			?>
		</select>
		<?php endif; ?>
		
		sorted
		<select class="superbar_field" name="sort">
			<option<?php if (@$parts['sort'] == 'date_desc') echo ' selected="selected"'; ?> value="date_desc">newest first</option>
			<option<?php if (@$parts['sort'] == 'date_asc')  echo ' selected="selected"'; ?> value="date_asc">oldest first</option>
			<option<?php if (@$parts['sort'] == 'title_az')  echo ' selected="selected"'; ?> value="title_az">title A-Z</option>
			<option<?php if (@$parts['sort'] == 'title_za')  echo ' selected="selected"'; ?> value="title_za">title Z-A</option>
			<option<?php if (@$parts['sort'] == 'eng_desc')  echo ' selected="selected"'; ?> value="eng_desc">most popular first</option>
			<option<?php if (@$parts['sort'] == 'eng_asc') 	 echo ' selected="selected"'; ?> value="eng_asc">least popular first</option>
			<option<?php if (@$parts['sort'] == 'up') 	 	 echo ' selected="selected"'; ?> value="up">date, upcoming</option>
			<option<?php if (@$parts['sort'] == 'dt_desc') 	 echo ' selected="selected"'; ?> value="dt_desc">more recent first</option>
			<option<?php if (@$parts['sort'] == 'dt_asc') 	 echo ' selected="selected"'; ?> value="dt_asc">less recent first</option>
		</select>
		<input type="submit" value="OK!" />
	</form>
</div>

<div id="blocks">
	<div class="column filtered entry_list" id="blocks_large">
		<?php if ($content): ?>
			
			<?php
			// create an array of content type names
			$types = array();
			foreach ($content_types->result() as $type)
				$types[$type->id] = $type->name;
			
			foreach ($content->result() as $entry):
				$content_id = $entry->id;
				$type_name	= $types[$entry->content_type_id];
			?>

			<div class="entry <?php echo alternator('even', 'odd'); ?>" id="entry_<?php echo $content_id; ?>">
				<h3 class=entry_title">
					<!-- Avatar -->
					<?php if ($entry->content_image): ?>
					<img class="content_list_avatar" src="<?php echo url_for_avatar($entry->content_image, $entry->id, 'content', 'large'); ?>" alt="" /><br />
					<?php endif; ?>
					<a style="line-height: 16px;" href="<?php echo content_url($entry); ?>"><?php echo htmlentities($entry->field1_value); ?></a>
					<?php echo !isset($parts['entry_type']) || @$parts['entry_type'] == 'all' ? "<span class=\"toe_tag tag_{$type_name}\">{$type_name}</span>" : ''; ?>
				</h3>
				
				<div class=entry_content" style="margin: 3px 0; line-height: 16px; width: 399px;">
					<?php echo ascii_to_entities(auto_link($this->Content_model->content_data($entry, false, true))); ?>
				</div>
				
				<?php if ($bricabox->allow_engagement): ?>
				<div class=entry_interation" style="float: right; z-index: 1337;">
					<span class="engage_small">
						<span class="engage_count_small">
							<?php echo $engage->small_count_for_entry($bricabox, $entry); ?>
						</span>
						<span class="engage_form_small">
							<?php echo $engage->small_form_for_entry($bricabox, $entry, $this->userland->current_user()); ?>
						</span>
					</span>
				</div>
				<?php endif; ?>
				
				<div class="clearfix"></div>
			</div>

			<?php endforeach; ?>

		<?php else: ?>
		<h1>Nothing has been added quite yet.</h1>
		<?php endif; ?>
	</div>
	
	<div class="column filtered" id="blocks_small">
		<?php
		foreach ($blocks as $i => $block_data)
		{
			$method				 = "small_{$block_data['data']->location}";
			$block_data['klass'] = BlockInstance::load_block_file(
				$block_data['template_path'],
				$block_data['parent']->name
			);
			$block_data['title'] = BlockInstance::title_for_block($block_data);
			
			echo "\t<!-- name: {$block_data['parent']->name} instance_id: {$block_data['data']->id} -->\n";
			echo "\t<div class=\"block_instance\" id=\"block_instance_{$block_data['data']->id}\">\n";
			echo "\t\t<h3>{$block_data['title']}</h3>\n";
			$block_data['klass']->$method($block_data, $content);
			echo "\n\t</div>\n\n";
		}
		?>
	</div>
</div>

<?php
function rss_token()
{
	global $BBX;
	if (!$BBX['bricabox']->privacy)
		return '/token/'.md5($BBX['bricabox']->id);
}
?>

<?php require_once LAYOUTPATH.'layout_footer.php'; ?>
